<!-- Main -->
<div class="page-header">
  <h2 class="text-center">Liste de toutes les brocantes</h2>
</div>

<div class="container">

  <div class="row featurette">
    <div class="col-md-4">
      <div class="panel-group" id="accordion">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h4 class="panel-title">
              <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">&raquo; Filtrer le contenu</a>
            </h4>
          </div>
          <div id="collapseOne" class="panel-collapse">
            <div class="panel-body">
              <form method="get">
                <label for="select" class="control-label">Catégorie des brocantes :</label><br>
                <select class="form-control" id="inputcategBroc" name="categBrocante">
                  <option value="categ_toutes">Toutes</option> 
                  <?php foreach ($categories as $k => $v){
                    echo '<option '; if((isset($_GET['categBrocante'])) and ($_GET['categBrocante'] == $v->id)) echo 'selected="selected" '; echo 'value="'.$v->id.'">'.$v->nom.'</option>';
                  };?>
                </select>
                <br>
                <label for="select" class="control-label">Etat des brocantes :</label><br>
                <div class="btn-group btn-group-sm" data-toggle="buttons">
                  <label class="btn btn-default <?php if((isset($_GET['etatBrocante'])) and ($_GET['etatBrocante'] == "venir")) echo 'active';?>">
                    <input type="radio" name="etatBrocante" value="venir">A venir
                  </label>
                  <label class="btn btn-default <?php if((isset($_GET['etatBrocante'])) and ($_GET['etatBrocante'] == "cours")) echo 'active';?>">
                    <input type="radio" name="etatBrocante" value="cours">En cours
                  </label>
                  <label class="btn btn-default <?php if((isset($_GET['etatBrocante'])) and ($_GET['etatBrocante'] == "passe")) echo 'active';?>">
                    <input type="radio" name="etatBrocante" value="passe">Passé
                  </label>
                  <label class="btn btn-default <?php if(((isset($_GET['etatBrocante'])) and ($_GET['etatBrocante'] == "toutes")) or (!isset($_GET['etatBrocante']))) echo 'active';?>">
                    <input type="radio" name="etatBrocante" value="toutes">Toutes
                  </label>
                </div>
                <br><br>
                <label for="select" class="control-label">Date des brocantes :</label><br>
                <div class='input-group date' id='inputdateBroc' name='dateBroc'>
                  <input type='text' class="form-control" id="inputdateBroc" name="dateBrocante" value="<?php if(isset($_GET['dateBrocante'])) echo $_GET['dateBrocante']; ?>"/>
                  <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
                </span>
              </div><hr>
              <button type="reset" class="btn btn-default" onclick="location.href='<?php echo Router::url("brocantes/index"); ?>'">Remise à zéro</button>
              <button type="submit" class="btn btn-primary">Filtrer</button>      
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>


  <div class="col-md-8 blog-main"> 
    <?php if (isset($brocantes[0])){ foreach ($brocantes as $k => $v): ?>
    <div class="blog-post">
      <h2><?php echo $v->nom.' - '; ?><span class="text-muted"><?php echo $v->lieu ?></span></h2>
      <h4>
        <?php if ((new DateTime($v->dateBroc))->format('Y-m-d') > (new DateTime())->format('Y-m-d')){ echo '<span class="label label-warning">A venir</span><span class="text-muted">';}
        else if ((new DateTime($v->dateBroc))->format('Y-m-d') == (new DateTime())->format('Y-m-d')){ echo '<span class="label label-success">En cours</span><span class="text-muted">';}
        else
          { echo '<span class="label label-default">Passé</span><span class="text-muted">';}?>

        <?php echo ' - '.strftime('%A, %e %B %Y', strtotime($v->dateBroc)) ?></span></h4>
        <p><?php echo substr(strip_tags(trim($v->description), '<b><br>'), 0, 300).' ...'; ?></p>
        <p><a class="btn btn-primary" role="button" href="<?php echo Router::url("brocantes/view/{$v->id}/$v->slug"); ?>">Voir les détails &raquo;</a></p>

      </div>
      <hr class="featurette-divider">

    <?php endforeach; }else{echo "<div class='jumbotron' style='text-align:center'><span style='font-size:4em' class='glyphicon glyphicon-eye-close'></span><h3>Pas de résultat</h3></div>";} ?>

    <div>
      <ul class="pagination" style="">
        <?php for ($i=1; $i <= $page; $i++): ?>
        <li <?php if($i==$this->request->page) echo 'class="active"'; ?>><a href="?page=<?php echo $i ?>"><?php echo $i ?></a></li>
      <?php endfor; ?>
    </ul>
  </div>
</div>
</div>
<script type="text/javascript">
$(function () {
  $('#inputdateBroc').datetimepicker({ language: 'fr', pickTime: false, });
});
</script>